import axios from 'axios';
import { message } from "ant-design-vue";
const env = import.meta.env;
const qz = env.VITE_NODE_ENV === 'development' ? env.VITE_API_URL : '/ytab';
const service = axios.create({
  baseURL: qz,
  timeout: 50000,
  headers: { 'Content-Type': 'application/json;charset=utf-8' }
});
// 请求拦截器
service.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截器
service.interceptors.response.use(
  async (response) => {
    const { code, msg } = response.data;
    if (code >= 200 && code < 300) {
      return response.data;
    }
    message.error(msg || '系统出错');
    return Promise.reject(new Error(msg || 'Error'));
  },
  (error) => {
    message.error(error.message);
    const $error = error;
    $error.isCancelRequest = axios.isCancel($error);
    return Promise.reject(error.message);
  }
);

// 导出 axios 实例
export default service;
